package com.sskj.zixun.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.zixun.R;
import com.sskj.zixun.bean.Banner;
import com.sskj.zixun.bean.PlatFormInfoBean;
import com.sskj.zixun.http.HttpConfig;
import com.sskj.zixun.ui.fragment.ZiXunReallyFragment;
import com.sskj.common.base.App;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;


public class ZixunReallyFragmentPresenter extends BasePresenter<ZiXunReallyFragment> {
    public void getDataList(int page, int pageSize) {
        httpService.getZiXunList(page, pageSize)
                .tag(this)
                .execute(new JsonCallBack<HttpData<PlatFormInfoBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<PlatFormInfoBean>> response) {
                        HttpData<PlatFormInfoBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            if (httpData.getData() != null && httpData.getData().getList() != null && httpData.getData().getList().size() != 0) {
                                mView.setData(response.body().getData().getList());
                            } else {
                                ToastUtil.showShort(App.INSTANCE.getString(R.string.zixunZixunReallyFragmentPresenter0));
                            }
                        }
                    }
                });
    }

    /**
     * 获取新闻资讯头部Banner
     */
    public void getBannerUrl() {
        httpService.getBannerZixun().execute(new JsonCallBack<HttpData<Banner>>() {
            @Override
            public void onSuccess(Response<HttpData<Banner>> response) {
                HttpData<Banner> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    mView.showBanner(response.body().getData());
                }
            }
        });
    }
}
